package com.ruitu.router_module.support.view;

import android.view.View;

import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.interfaces.OnItemLongClickListener;
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
import com.github.jdsjlzx.interfaces.OnRefreshListener;
import com.ruitu.arad.Arad;
import com.ruitu.arad.base.base_list.BaseRefreshFragment;

import androidx.recyclerview.widget.GridLayoutManager;

public abstract class BaseRefreshGridFragment extends BaseRefreshFragment {
    @Override
    protected void initRecyclerView(View v) {
        lRecyclerView = findRecyclerView(v);
        progressLayout = findProgressLayout(v);
        if (null != lRecyclerView) {

            if (null != Arad.refreshHeader) {// new CustomRefreshHeader(context)
                lRecyclerView.setRefreshHeader(Arad.refreshHeader);
            }

            lRecyclerView.setAdapter(lAdapter);
            lRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));

//            setLoadMoreEnabled(false);//默认不开启加载更多功能
            //设置底部加载文字提示
            lRecyclerView.setFooterViewHint("努力加载中", "加载完成", "加载失败,点击重试");

            lRecyclerView.setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh() {
                    reqFirst();
                }
            });
            lRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
                @Override
                public void onLoadMore() {
                    reqMore();
                }
            });

            if (null != lAdapter) {
                //设置点击事件
                lAdapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(View v, int position) {
                        BaseRefreshGridFragment.this.onItemClick(v, position);
                    }
                });
                lAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {
                    @Override
                    public void onItemLongClick(View v, int position) {
                        BaseRefreshGridFragment.this.onItemLongClick(v, position);
                    }
                });
            }
        }
    }
}
